package net.chenlin.dp.modules.newBusiness.entity.dto;

import lombok.Data;
import net.chenlin.dp.common.utils.JSONUtils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Author: Yansgm
 * @Description:
 * @Date: 2025-04-25 14:42:49
 */
@Data
public class MonitorDataDto {

    private String monitor_id;

    private String timestamp;

    private String meteringstart;

    private String meteringend;

    private Meteringvalue meteringvalue;

    //private Currentvalue currentvalue;

    private BigDecimal currentA;

    private BigDecimal currentB;

    private BigDecimal currentC;

    private Voltagevalue voltagevalue;

    public static void main(String[] args) throws ParseException {
        String content = "{\"monitor_id\":\"867553069567550\",\"timestamp\":\"2025-04-27T16:45:00Z\",\"meteringstart\":\"2025-04-27T16:30:01Z\",\"meteringend\":\"2025-04-27T16:45:03Z\",\"meteringvalue\":{\"meteringA\":2.11,\"meteringB\":2.10,\"meteringC\":2.11},\"currentA\":3.624,\"currentB\":3.604,\"currentC\":3.622,\"voltagevalue\":{\"voltageA\":231.9,\"voltageB\":231.8,\"voltageC\":232.4}}";
        MonitorDataDto dto  = JSONUtils.jsonToBean(content,MonitorDataDto.class);
        System.out.println(dto);
        // 解析ISO日期时间字符串
        ZonedDateTime zonedDateTime = ZonedDateTime.parse(dto.getTimestamp());
        // 定义目标格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 格式化日期时间
        String formattedDateTime = zonedDateTime.format(formatter);

        System.out.println(formattedDateTime); // 输出: 2025-04-27 16:45:00
        SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
        Date date = sdf.parse(formattedDateTime);
        System.out.println(date);

        String TOPIC = "monitor/867553069567550/data";
        int i = TOPIC.indexOf("/");
        int y = TOPIC.lastIndexOf("/");
        String substring = TOPIC.substring(i+1, y);
        System.out.println(substring);

    }
}
